package com.zhupf.binaryTree;


import java.util.ArrayList;
import java.util.List;

/**
 * @author zhupf
 * @date 2023年11月24日 15:36
 * @Description
 *
 * 101. 对称二叉树
 */
public class IsSymmetric {

    public static void main(String[] args) {
//        TreeNode root = new TreeNode(1,new TreeNode(2,null,new TreeNode(3)),new TreeNode(2,null,new TreeNode(3)));
        TreeNode root = new TreeNode(1,null,new TreeNode(2));
        IsSymmetric i = new IsSymmetric();
        System.out.println(i.isSymmetric(root));
    }

    public boolean isSymmetric(TreeNode root) {
        return isSymmetric(root.left,root.right);
    }

    public boolean isSymmetric(TreeNode left,TreeNode right) {
        if(left == null && right == null){
            return true;
        }
        if(left == null && right != null){
            return false;
        }
        if(left != null && right == null){
            return false;
        }

        if(left.val!= right.val){
            return false;
        }
        return isSymmetric(left.left,right.right) && isSymmetric(left.right,right.left);
    }


}
